define(function(require,exports,module){
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var user = require("store").get("user");

	
	module.exports = {
		initComponent: function(params,widget){
			var subnav = new Subnav({
				parentNode: ".J-subnav",
				model: {
					title: "合同签约",
					items: [{
						id:"search",
						type: "search",
						placeholder: "会员/合同号/会员证号",
						handler: function(str){
							aw.ajax({
								url: "api/travelcontractcharge/search",
								data: {
									s: str,
									properties: "travelContract.member.personalInfo.name,travelContract.memberCertificates,travelContract.contactNo",
									fetchProperties: "*,travelContract.*,travelContract.member.personalInfo.*,travelContract.productRule.*," +
     								"travelContract.productRule.product.*,travelContract.productType.*,travelContract.member.personalInfo.areaAddress.*," +
     								"travelContract.productBatch.*,travelContract.status.*,status.*" 
								},
								success: function(data){
									widget.get("grid").setData(data);
								}
							});
						}
					},{
						id : "servicePoint",
						text : "服务点",
						tip : "服务点",
						items:user.privateServicePoints,
						type : "buttongroup",
						keyField : "pkServicePoint",
						valueField : "name",
						handler:function(key,element){	
							widget.get("grid").refresh();
						}
					},{
						id:"status",
						type: "buttongroup",
						tip: "签约状态",
						items: [{
							key: "Initial",
							value: "初始"
						},{
							key: "Valid",
							value: "有效"
						},{
							key: "Finish",
							value: "终止"
						}],
						all: {
							show: true,
							position: "top"
						},
						handler: function(key){
							widget.get("grid").refresh();
						}
					},{
			            id: "dateRange",
			            type: "daterange",
			            ranges: {
			                "今天": [moment().startOf("days"), moment().endOf("days")],
			                "本月": [moment().startOf("month"), moment().endOf("month")]
			            },
			            defaultRange: "本月",
			            minDate: "1930-05-31",
			            maxDate: "2020-12-31",
			            handler: function(time) {
			            	widget.get("grid").refresh();
			            },
			            tip: "签约日期"
			        },{
						id: "add",
						type: "button",
						text: "新增",
						handler: function(){
							widget.get("form").reset();
							//widget.get("form").setValue("createTime",moment());
							widget.show([".J-form"]).hide([".J-grid"]);
							widget.get("subnav").hide(["add","search","status","servicePoint","dateRange"]).show(["back"]);
						}
					},{
						id:"back",
						type:"button",
						text:"返回",
						show : false,
						handler:function(){
							widget.show([".J-grid"]).hide([".J-form"]);
							widget.get("subnav").hide(["back"]).show(["add","search","status","servicePoint","dateRange"]);
							//widget.get("grid").refresh();
						}
					}]
				}
			});
			
			widget.set("subnav",subnav);
		}
	};
});